package com.flowable.controller;

import com.flowable.common.result.CommonResult;
import com.flowable.service.ProcDefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程定义 控制器
 */
@RestController
@RequestMapping("/procDef")
public class ProcDefController {

    @Autowired
    private ProcDefService procDefService;

    /**
     * 手动部署
     *
     * @param xml_name bpmn.xml文件名
     * @param name     流程定义名
     */
    @GetMapping("/manualDeploy")
    public CommonResult manualDeploy(@RequestParam(value = "xml_name") String xml_name,
                                     @RequestParam(value = "name") String name) {
        return procDefService.manualDeploy(xml_name, name);
    }

    /**
     * 查询 流程定义
     */
    @GetMapping("/query")
    public CommonResult procDefQuery(@RequestParam(value = "deployId") String deployId) {
        return procDefService.procDefQuery(deployId);
    }

    /**
     * 删除 流程定义
     *
     * @param deployId deploymentId
     * @param cascade  cascade=false||null   如果部署的流程启动了，不允许删除
     *                 cascade=true          级联删除，如果流程启动了，相关的任务一并会被删除
     */
    @GetMapping("/delete")
    public CommonResult procDefDelete(@RequestParam(value = "deployId") String deployId,
                                      @RequestParam(value = "cascade") boolean cascade) {
        return procDefService.procDefDelete(deployId, cascade);
    }
}
